package com.yycx.module.user.provider.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.base.service.impl.BaseServiceImpl;
import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.common.mybatis.query.CriteriaSave;
import com.yycx.module.user.provider.mapper.SysKeywordMapper;
import com.yycx.module.user.client.entity.SysKeyword;
import com.yycx.module.user.provider.service.SysKeywordService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 关键词接口实现类
 *
 * @author flyme
 * @date 2020-03-22
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysKeywordServiceImpl extends BaseServiceImpl<SysKeywordMapper, SysKeyword> implements SysKeywordService {

    @Override
    public ResultBody beforeAdd(CriteriaSave cs, SysKeyword keyword, EntityMap extra) {

        SysKeyword one = getOne(new QueryWrapper<SysKeyword>().lambda().eq(SysKeyword::getContent, keyword.getContent()));
        if(FlymeUtils.isNotEmpty(one)){
            removeById(one);
        }
        return ResultBody.ok();
    }



    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody beforePageList(CriteriaQuery<SysKeyword> cq, SysKeyword keyword, EntityMap requestMap) {
      cq.eq(SysKeyword.class,"groupType");
      cq.like(SysKeyword.class,"content");
      cq.orderByAsc("sortOrder");
      return ResultBody.ok();
    }
}
